package com.cmccgz.baselibrary.utils;

import android.text.TextUtils;

import static android.R.attr.password;

/**
 * Created by Huang on 2017/5/25.
 */
public class RegularUtil {

    public static boolean isMobileNumber(String mobiles) {
        String telRegex = "^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$";
        return !TextUtils.isEmpty(mobiles) && mobiles.matches(telRegex);
    }

    public static boolean isPassword(String password) {
        String passwordRegex = "^[A-Za-z0-9]{6,12}$";
        return !TextUtils.isEmpty(password) && password.matches(passwordRegex);
    }
    public static boolean isSMSKey(String smskey) {
        String passwordRegex = "^[0-9]{6}$";
        return !TextUtils.isEmpty(smskey) && smskey.matches(passwordRegex);
    }

    /**
     * 验证是否合格的身份证号码（15位和18位）
     * @param idCardNumber 身份证号码
     * @return 是否合格
     */
    public static boolean isIDCardNumber(String idCardNumber) {
        String idCardRegex = "(^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$)|(^[1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}$)";
        return !TextUtils.isEmpty(idCardNumber) && idCardNumber.matches(idCardRegex);
    }
}
